<script setup>
import { ref } from 'vue'
import { useHealthStore } from '../stores/healthStore'

const store = useHealthStore()
const goalsForm = ref({ ...store.goals })

const setGoals = () => {
  store.setGoals(goalsForm.value)
  alert('目标已更新！')
}
</script>

<template>
  <div class="goals-view">
    <h1>目标管理</h1>
    <p class="subtitle">设定您的健康目标，系统将帮助您跟踪进度</p>
    
    <div class="goals-form">
      <form @submit.prevent="setGoals">
        <div class="form-group">
          <label>每周运动目标（分钟）</label>
          <input 
            type="number" 
            v-model.number="goalsForm.exercise" 
            min="30" 
            max="600" 
            required>
          <div class="hint">建议每周150-300分钟中等强度运动</div>
        </div>
        
        <div class="form-group">
          <label>每日卡路里目标（大卡）</label>
          <input 
            type="number" 
            v-model.number="goalsForm.calories" 
            min="800" 
            max="4000" 
            required>
          <div class="hint">成人每日建议摄入2000-2500大卡</div>
        </div>
        
        <div class="form-group">
          <label>每日睡眠目标（小时）</label>
          <input 
            type="number" 
            v-model.number="goalsForm.sleep" 
            min="4" 
            max="12" 
            step="0.5" 
            required>
          <div class="hint">建议每日7-9小时优质睡眠</div>
        </div>
        
        <button type="submit">保存目标</button>
      </form>
      
      <div class="current-goals">
        <h2>当前目标</h2>
        <div class="goal-card">
          <div class="goal-icon">🏃‍♂️</div>
          <div class="goal-details">
            <h3>运动目标</h3>
            <p>{{ store.goals.exercise }} 分钟/周</p>
          </div>
        </div>
        
        <div class="goal-card">
          <div class="goal-icon">🍽️</div>
          <div class="goal-details">
            <h3>饮食目标</h3>
            <p>{{ store.goals.calories }} 大卡/天</p>
          </div>
        </div>
        
        <div class="goal-card">
          <div class="goal-icon">😴</div>
          <div class="goal-details">
            <h3>睡眠目标</h3>
            <p>{{ store.goals.sleep }} 小时/天</p>
          </div>
        </div>
      </div>
    </div>
    
    <div class="recommendations">
      <h2>健康目标建议</h2>
      <p>根据世界卫生组织（WHO）的建议：</p>
      <ul>
        <li>成年人每周至少进行150-300分钟的中等强度有氧运动</li>
        <li>每日饮食摄入量应根据年龄、性别、体重和活动水平调整</li>
        <li>18-64岁成人每晚应保证7-9小时的睡眠</li>
        <li>保持水分平衡，每日饮用约2升水</li>
        <li>减少久坐时间，每小时起身活动5分钟</li>
      </ul>
    </div>
  </div>
</template>

<style scoped>
.goals-view {
  padding: 20px;
  max-width: 1000px;
  margin: 0 auto;
}

h1 {
  color: #2c3e50;
  margin-bottom: 5px;
}

.subtitle {
  color: #7f8c8d;
  margin-top: 0;
  margin-bottom: 30px;
  font-size: 18px;
}

.goals-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  margin-bottom: 40px;
}

.form-group {
  margin-bottom: 25px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #2c3e50;
}

input {
  width: 100%;
  padding: 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
}

.hint {
  font-size: 14px;
  color: #7f8c8d;
  margin-top: 6px;
}

button[type="submit"] {
  background: #3498db;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 14px 30px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  transition: background 0.3s ease;
}

button[type="submit"]:hover {
  background: #2980b9;
}

.current-goals {
  background: white;
  border-radius: 16px;
  padding: 25px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.current-goals h2 {
  margin-top: 0;
  color: #2c3e50;
  margin-bottom: 20px;
}

.goal-card {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 15px;
  margin-bottom: 15px;
  border-radius: 12px;
  background: #f9f9f9;
}

.goal-icon {
  font-size: 28px;
  width: 60px;
  height: 60px;
  background: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.goal-details h3 {
  margin: 0 0 5px;
  color: #2c3e50;
}

.goal-details p {
  margin: 0;
  color: #7f8c8d;
  font-size: 18px;
}

.recommendations {
  background: white;
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.recommendations h2 {
  color: #2c3e50;
  margin-top: 0;
}

.recommendations ul {
  padding-left: 20px;
}

.recommendations li {
  margin-bottom: 10px;
  line-height: 1.6;
  color: #555;
}

@media (max-width: 768px) {
  .goals-form {
    grid-template-columns: 1fr;
  }
}
</style>